home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sound / fmopl.h < prev    next >
C/C++ Source or Header  |  2000-01-15  |  6KB  |  161 lines

  1. #ifndef __FMOPL_H_
  2. #define __FMOPL_H_
  3.  
  4. #define BUILD_YM3812 (HAS_YM3812)
  5. #define BUILD_YM3526 (HAS_YM3526)
  6. #define BUILD_Y8950  (HAS_Y8950)
  7.  
  8. /* compiler dependence */
  9. #ifndef OSD_CPU_H
  10. #define OSD_CPU_H
  11. typedef unsigned char    UINT8;   /* unsigned  8bit */
  12. typedef unsigned short    UINT16;  /* unsigned 16bit */
  13. typedef unsigned int    UINT32;  /* unsigned 32bit */
  14. typedef signed char        INT8;    /* signed  8bit   */
  15. typedef signed short    INT16;   /* signed 16bit   */
  16. typedef signed int        INT32;   /* signed 32bit   */
  17. #endif
  18.  
  19. #if BUILD_Y8950
  20. #include "ymdeltat.h"
  21. #endif
  22.  
  23. typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
  24. typedef void (*OPL_IRQHANDLER)(int param,int irq);
  25. typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
  26. typedef void (*OPL_PORTHANDLER_W)(int param,unsigned char data);
  27. typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
  28.  
  29. /* !!!!! here is private section , do not access there member direct !!!!! */
  30.  
  31. #define OPL_TYPE_WAVESEL   0x01  /* waveform select    */
  32. #define OPL_TYPE_ADPCM     0x02  /* DELTA-T ADPCM unit */
  33. #define OPL_TYPE_KEYBOARD  0x04  /* keyboard interface */
  34. #define OPL_TYPE_IO        0x08  /* I/O port */
  35.  
  36. /* ---------- OPL one of slot  ---------- */
  37. typedef struct fm_opl_slot {
  38.     INT32 TL;        /* total level     :TL << 8            */
  39.     INT32 TLL;        /* adjusted now TL                     */
  40.     UINT8  KSR;        /* key scale rate  :(shift down bit)   */
  41.     INT32 *AR;        /* attack rate     :&AR_TABLE[AR<<2]   */
  42.     INT32 *DR;        /* decay rate      :&DR_TALBE[DR<<2]   */
  43.     INT32 SL;        /* sustin level    :SL_TALBE[SL]       */
  44.     INT32 *RR;        /* release rate    :&DR_TABLE[RR<<2]   */
  45.     UINT8 ksl;        /* keyscale level  :(shift down bits)  */
  46.     UINT8 ksr;        /* key scale rate  :kcode>>KSR         */
  47.     UINT32 mul;        /* multiple        :ML_TABLE[ML]       */
  48.     UINT32 Cnt;        /* frequency count :                   */
  49.     UINT32 Incr;    /* frequency step  :                   */
  50.     /* envelope generator state */
  51.     UINT8 eg_typ;    /* envelope type flag                  */
  52.     UINT8 evm;        /* envelope phase                      */
  53.     INT32 evc;        /* envelope counter                    */
  54.     INT32 eve;        /* envelope counter end point          */
  55.     INT32 evs;        /* envelope counter step               */
  56.     INT32 evsa;    /* envelope step for AR :AR[ksr]       */
  57.     INT32 evsd;    /* envelope step for DR :DR[ksr]       */
  58.     INT32 evsr;    /* envelope step for RR :RR[ksr]       */
  59.     /* LFO */
  60.     UINT8 ams;        /* ams flag                            */
  61.     UINT8 vib;        /* vibrate flag                        */
  62.     /* wave selector */
  63.     INT32 **wavetable;
  64. }OPL_SLOT;
  65.  
  66. /* ---------- OPL one of channel  ---------- */
  67. typedef struct fm_opl_channel {
  68.     OPL_SLOT SLOT[2];
  69.     UINT8 CON;            /* connection type                     */
  70.     UINT8 FB;            /* feed back       :(shift down bit)   */
  71.     INT32 *connect1;    /* slot1 output pointer                */
  72.     INT32 *connect2;    /* slot2 output pointer                */
  73.     INT32 op1_out[2];    /* slot1 output for selfeedback        */
  74.     /* phase generator state */
  75.     UINT32  block_fnum;    /* block+fnum      :                   */
  76.     UINT8 kcode;        /* key code        : KeyScaleCode      */
  77.     UINT32  fc;            /* Freq. Increment base                */
  78.     UINT32  ksl_base;    /* KeyScaleLevel Base step             */
  79.     UINT8 keyon;        /* key on/off flag                     */
  80. } OPL_CH;
  81.  
  82. /* OPL state */
  83. typedef struct fm_opl_f {
  84.     UINT8 type;            /* chip type                        */
  85.     int clock;            /* master clock  (Hz)                */
  86.     int rate;            /* sampling rate (Hz)                */
  87.     double freqbase;    /* frequency base                    */
  88.     double TimerBase;    /* Timer base time (==sampling time) */
  89.     UINT8 address;        /* address register                  */
  90.     UINT8 status;        /* status flag                       */
  91.     UINT8 statusmask;    /* status mask                       */
  92.     UINT32 mode;        /* Reg.08 : CSM , notesel,etc.       */
  93.     /* Timer */
  94.     int T[2];            /* timer counter       */
  95.     UINT8 st[2];        /* timer enable        */
  96.     /* FM channel slots */
  97.     OPL_CH *P_CH;        /* pointer of CH       */
  98.     int    max_ch;            /* maximum channel     */
  99.     /* Rythm sention */
  100.     UINT8 rythm;        /* Rythm mode , key flag */
  101. #if BUILD_Y8950
  102.     /* Delta-T ADPCM unit (Y8950) */
  103.     YM_DELTAT *deltat;            /* DELTA-T ADPCM       */
  104. #endif
  105.     /* Keyboard / I/O interface unit (Y8950) */
  106.     UINT8 portDirection;
  107.     UINT8 portLatch;
  108.     OPL_PORTHANDLER_R porthandler_r;
  109.     OPL_PORTHANDLER_W porthandler_w;
  110.     int port_param;
  111.     OPL_PORTHANDLER_R keyboardhandler_r;
  112.     OPL_PORTHANDLER_W keyboardhandler_w;
  113.     int keyboard_param;
  114.     /* time tables */
  115.     INT32 AR_TABLE[75];    /* atttack rate tables */
  116.     INT32 DR_TABLE[75];    /* decay rate tables   */
  117.     UINT32 FN_TABLE[1024];  /* fnumber -> increment counter */
  118.     /* LFO */
  119.     INT32 *ams_table;
  120.     INT32 *vib_table;
  121.     INT32 amsCnt;
  122.     INT32 amsIncr;
  123.     INT32 vibCnt;
  124.     INT32 vibIncr;
  125.     /* wave selector enable flag */
  126.     UINT8 wavesel;
  127.     /* external event callback handler */
  128.     OPL_TIMERHANDLER  TimerHandler;        /* TIMER handler   */
  129.     int TimerParam;                        /* TIMER parameter */
  130.     OPL_IRQHANDLER    IRQHandler;        /* IRQ handler    */
  131.     int IRQParam;                        /* IRQ parameter  */
  132.     OPL_UPDATEHANDLER UpdateHandler;    /* stream update handler   */
  133.     int UpdateParam;                    /* stream update parameter */
  134. } FM_OPL;
  135.  
  136. /* ---------- Generic interface section ---------- */
  137. #define OPL_TYPE_YM3526 (0)
  138. #define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
  139. #define OPL_TYPE_Y8950  (OPL_TYPE_ADPCM|OPL_TYPE_KEYBOARD|OPL_TYPE_IO)
  140.  
  141. FM_OPL *OPLCreate(int type, int clock, int rate);
  142. void OPLDestroy(FM_OPL *OPL);
  143. void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int channelOffset);
  144. void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param);
  145. void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int param);
  146. /* Y8950 port handlers */
  147. void OPLSetPortHandler(FM_OPL *OPL,OPL_PORTHANDLER_W PortHandler_w,OPL_PORTHANDLER_R PortHandler_r,int param);
  148. void OPLSetKeyboardHandler(FM_OPL *OPL,OPL_PORTHANDLER_W KeyboardHandler_w,OPL_PORTHANDLER_R KeyboardHandler_r,int param);
  149.  
  150. void OPLResetChip(FM_OPL *OPL);
  151. int OPLWrite(FM_OPL *OPL,int a,int v);
  152. unsigned char OPLRead(FM_OPL *OPL,int a);
  153. int OPLTimerOver(FM_OPL *OPL,int c);
  154.  
  155. /* YM3626/YM3812 local section */
  156. void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length);
  157.  
  158. void Y8950UpdateOne(FM_OPL *OPL, INT16 *buffer, int length);
  159.  
  160. #endif
  161.